home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
challenge
/
12.04-Apr96
/
LifeTestCode DR3.sit
/
Life TestCode DR3
/
LifeFile.h
< prev
next >
Wrap
Text File
|
1996-03-30
|
2KB
|
77 lines
/* LifeFile.h */
/* ©Ludovic Nicolle 1996 */
/*
The LifeFile file format is as simpler as possible and follow
the following pattern
The first 4 bytes are a long, numRuns, that defines how many
LifeRuns are stored in the LifeFile.
After that, there is a LifeRun structure followed by as many
BitMap data as (steps+1), each preceded by a long indicating the
stepvalue.
If numRuns is greater than 1, new LifeRuns
are simply appended with their associated data.
To obtain the nth LifeRun in the file, one must go through each
LifeRun to compute the next offset and so on. This is not an
efficient random access file format, but I don't think this to be
important here.
*/
#pragma options align=power
typedef struct{
long stepvalue;
BitMap cellsBM;
} BitMapStep, *BitMapStepPtr;
typedef struct{
long stepvalue;
long bmdata[]; /*the BitMap data itself, as raw data of which
size is defined by rowBytes * height */
} bmDataStep, bmDataStepPtr;/*this is only for definition purposes.
I don't use this type in the code */
typedef struct{
long maxGen; /* Generations to compute */
short birthRules; /* see problem statement */
short deathRules; /* see problem statement */
long computedGen; /* nb of computed generations */
short filler1;
short rbytes; /*width in bytes of each line of the BitMap*/
Rect worldSize; /* Rect enclosing the cells BitMap
This defines the bounds of each bitmap in the run
April challenge statement says topleft= {0, 0}*/
long steps; /* nb of steps recorded in this run */
} LifeRun, *LifeRunPtr;
#pragma options align=reset
#define LifeFileType 'LIFE'
#define MutantLifeCreator 'MULI'
#define kMaxRuns 32 /*Maximum number of runs in a single file*/
#define tooManyRunsErr 3064
#define lifeFileCorruptErr 3065
#define noRunsErr 3066
#define badBitMapSizeErr 3067
#define runAbsentErr 3068
#define stepAbsentErr 3069
/* prototypes */
OSErr CreateLifeFile(short *refNum, FSSpec *fileSpec);
OSErr OpenLifeFile(short *refNum, FSSpec *fileSpec);
OSErr CloseLifeFile(short *refNum);
OSErr AppendLifeRun(short refNum, LifeRun *theRun);
OSErr SetComputedGen(short refNum, long whichRun, long computedGen);
OSErr AppendLifeWorld(short refNum, BitMapStep *lifeWorld);
OSErr GetRunNumber(short refNum, long *outRuns);
OSErr ReadLifeRun(short refNum, LifeRun *theRun, long whichRun);
OSErr ReadLifeWorld(short refNum, BitMapStep *lifeWorld, long whichRun, long step);